Home:ALL Converter>no matching function error [templates]

no matching function error [templates]

Ask Time:2010-11-18T10:57:25         Author:FooBar

Json Formatter

Why doesn't the following code compile?

template <class T>
void foo_bar(T =5 , T = 10 , T = 15)
{
}

int main()
{
   foo_bar();
}

I get this error no matching function for call to 'foo_bar()'. How to fix the error?

Author:FooBar,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/4211273/no-matching-function-error-templates
Prasoon Saurav :

The type of default arguments in a function cannot help in deducing the template type-parameter. T cannot be deduced in any case when you call the function like foo_bar() and so you get the error.\n\nSo try this foo_bar<int>();. In this case there won't be any such problem because the type of T is explicitly specified.",
2010-11-18T03:00:06
yy